package org.scau.studentevaluation.config;

import feign.codec.Decoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;

/**
 * @ClassName: ConverterConfig
 * @Description: TODO  解码器
 * @Author: sunslikes
 * @Date: 2020/9/4 22:29
 * @Version: 1.0
 */
@Configuration
public class ConverterConfig {

    /**
     * 替代feign的解码器1
     * 解决不能接受string类型的bug,继续使用feign原生解码器，进行拓展
     * @return
     */
//    @Bean
    public Decoder feignDecoder1() {
        WxMessageConverter wxMessageConverter = new WxMessageConverter();
        ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(wxMessageConverter);
        return new SpringDecoder(objectFactory);
    }

    /**
     * 替代feign原生解码器的解码器2
     * 自动拆箱，反正就是对返回的统一结果进行处理，具体可查看解码器
     * @return
     */
    @Bean
    public Decoder feignDecoder2() {
        return new FeignResultDecoder();
    }
}
